package com.example.tidycalendartest;

import java.util.Calendar;
import java.util.Date;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//This is how we write to a text field in Android
		//The text will be overwritten further down in this function.
		EditText editText = (EditText) findViewById(R.id.editText1);
		editText.setText("Events in the database:");
		
		//The DatabaseHelper will prepare the database on the first and subsequent uses		
		DatabaseHelper dbh = new DatabaseHelper(this);
		
		//The EventList class is to read and write events from the database
		EventList list = new EventList(dbh.getWritableDatabase());
		
		//Create an event and store it to the database
		String desc = "Description";
		String name = "Test name";
		int event_id = 1;
		int cat_id = 1;
		
		//Start and end dates will differ by 1 second
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.SECOND, 1);
		
		Date start = new Date();
		Date end = cal.getTime();
		
		Event e = new Event(name, desc, cat_id, start, end);
		
		//This writes a new event to the database
		list.add(e);
		
		//Every time the app is run it will have 1 more event in the database.
		editText.setText("Event count: " + list.getCount());
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
